﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
using System.Data.SqlClient;
using DataHelper;
using Utils;

namespace DAL
{
    public class TeacherDao
    {

        public bool Insert(string tableName, SortedDictionary<string, string> sdList)
        {
            return new BuiltSQL().InsertTable(tableName, sdList);
        }


        public bool Update(string tableName, SortedDictionary<string, string> sdList)
        {
            return new BuiltSQL().UpdateTable(tableName, sdList);
        }

        public bool DeleteOneInfo(string teacherCode)
        {
            return SQLHelper.ExecuteSqlWithTransaction("Delete from Admin_Train_Teacher Where TeacherCode=" + teacherCode);
        }
        //获取一条记录
        public DataTable GetOneInfo(string teacherCode)
        {
            return SQLHelper.ExecuteSqlGetDrToDt("Select * from Admin_Train_Teacher Where TeacherCode=" + teacherCode);
        }
        public bool IsExistTeacherCode(string code)
        {
            DataTable dt = GetOneInfo(code);
            if (dt == null) return false;
            if (dt.Rows.Count > 0) return true;
            else
                return false;

        }
        //SQL
        public string GetSQL(string serWord, string statu)
        {

            StringBuilder strSQL = new StringBuilder("Select * From Admin_Train_Teacher Where statu like '%" + statu + "%' ");
            if (!string.IsNullOrWhiteSpace(serWord))
                strSQL.Append(" And (CnName Like '%" + serWord + "%')");

            return strSQL.ToString();
        }
        //列表
        public DataTable GetLists(string serWord, string statu)
        {
            DataTable dt = SQLHelper.ExecuteSqlGetDrToDt(GetSQL(serWord, statu));
            return dt;
        }
    }
}
